using System;
using System.Collections.Generic;
using System.Text;

using NHibernate;
using Zwms.Data.BusinessObjects;
using Zwms.Data.Base;
using Zwms.Data.CommonObject;
using NHibernate.Criterion;
using System.Reflection;

namespace Zwms.Data.ManagerObjects
{
    public partial interface ISysDictManager : IManagerBase<Zwms.Data.BusinessObjects.SysDict, string>
    {
        // Get Methods
        SysDict GetById(System.String dictKind, System.String dictKey);
    }

    partial class SysDictManager : ManagerBase<Zwms.Data.BusinessObjects.SysDict, string>, ISysDictManager
    {
        #region Constructors

        public SysDictManager()
            : base()
        {
        }
        public SysDictManager(INHibernateSession session)
            : base(session)
        {
        }

        #endregion

        #region Get Methods

        public override SysDict GetById(string id)
        {
            string[] keys = id.Split('^');

            if (keys.Length != 2)
                throw new Exception("Invalid Id for SysDictManager.GetById");

            return GetById(keys[0], keys[1]);
        }
        public SysDict GetById(System.String dictKind, System.String dictKey)
        {
            ICriteria criteria = Session.GetISession().CreateCriteria(typeof(SysDict));

            criteria.Add(NHibernate.Criterion.Expression.Eq("DictKind", dictKind));
            criteria.Add(NHibernate.Criterion.Expression.Eq("DictKey", dictKey));

            SysDict result = (SysDict)criteria.UniqueResult();

            if (result == null)
                throw new NHibernate.ObjectDeletedException("", null, null);

            return result;
        }

        #endregion
    }
}